export function judge(chessData) {
    let countBlack = 0;
    let countWhite = 0;

    // 列判断
    for (let i = 0; i < 15; i++){
        countBlack = 0;
        countWhite = 0;
        for (let j = 0; j < 15; j++){
            if (chessData[i][j] === "b"){
                countBlack++
                countWhite = 0
                if (countBlack === 5){
                    return 1
                }
            } else {
                countBlack = 0;
            }

            if (chessData[i][j] === "w"){
                countWhite++
                countBlack = 0
                if (countWhite === 5){
                    return 0
                }
            } else {
                countWhite = 0;
            }
        }
    }


    // 行判断
    for (let i = 0; i < 15; i++){
        countBlack = 0;
        countWhite = 0;
        for (let j = 0; j < 15; j++){
            if (chessData[j][i] === "b"){
                countBlack++
                countWhite = 0
                if (countBlack === 5){
                    return 1
                }
            } else {
                countBlack = 0;
            }

            if (chessData[j][i] === "w"){
                countWhite++
                countBlack = 0
                if (countWhite === 5){
                    return 0
                }
            } else {
                countWhite = 0;
            }
        }
    }


    for (let i =0; i < 15; i++){
        for (let j = 0; j < 15 - i; j++){
            const item = chessData[j][i + j]
            if (item === 'b'){
                countBlack++
                countWhite = 0
                if (countBlack===5){
                    return 1
                }
            } else {
                countBlack = 0
            }

            if (item === 'w'){
                countWhite++
                countBlack = 0
                if (countWhite === 5){
                    return 0
                }
            } else {
                countWhite = 0
            }
        }
    }

    for (let i = 0; i < 15; i++){
        for (let j = i; j < 15; j++){
            const item = chessData[j][j - i]
            if (item === 'b'){
                countBlack++
                countWhite = 0
                if (countBlack===5){
                    return 1
                }
            } else {
                countBlack = 0
            }

            if (item === 'w'){
                countWhite++
                countBlack = 0
                if (countWhite === 5){
                    return 0
                }
            } else {
                countWhite = 0
            }
        }
    }


    for (let l = 14; l > -1; l--){
        for (let i = l; i > -1; i--){
            const item = chessData[i][l - i]
            if (item === 'b'){
                countBlack++
                countWhite = 0
                if (countBlack===5){
                    return 1
                }
            } else {
                countBlack = 0
            }

            if (item === 'w'){
                countWhite++
                countBlack = 0
                if (countWhite === 5){
                    return 0
                }
            } else {
                countWhite = 0
            }
        }
    }


    for (let l = 0; l < 15; l++){
        for (let i = 14; i > l - 1; i--){
            const item = chessData[i][15 + l - i - 1]
            if (item === 'b'){
                countBlack++
                countWhite = 0
                if (countBlack===5){
                    return 1
                }
            } else {
                countBlack = 0
            }

            if (item === 'w'){
                countWhite++
                countBlack = 0
                if (countWhite === 5){
                    return 0
                }
            } else {
                countWhite = 0
            }
        }
    }

    return 10086
}
